# Scrapy settings for stock_scrapy project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = "stock_scrapy"

SPIDER_MODULES = ["stock_scrapy.spiders"]
NEWSPIDER_MODULE = "stock_scrapy.spiders"


# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = "stock_scrapy (+http://www.yourdomain.com)"

# Obey robots.txt rules
ROBOTSTXT_OBEY = True

# Configure maximum concurrent requests performed by Scrapy (default: 16)
# CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
# DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
# CONCURRENT_REQUESTS_PER_DOMAIN = 16
# CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
# COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
# TELNETCONSOLE_ENABLED = False

# Override the default request headers:
# DEFAULT_REQUEST_HEADERS = {
#    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
#    "Accept-Language": "en",
# }

# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
#    "stock_scrapy.middlewares.StockScrapySpiderMiddleware": 543,
# }

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# DOWNLOADER_MIDDLEWARES = {
#    "stock_scrapy.middlewares.StockScrapyDownloaderMiddleware": 543,
# }

# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
#    "scrapy.extensions.telnet.TelnetConsole": None,
# }

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
# ITEM_PIPELINES = {
#    "stock_scrapy.pipelines.StockScrapyPipeline": 300,
# }

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
# AUTOTHROTTLE_ENABLED = True
# The initial download delay
# AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
# AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
# HTTPCACHE_ENABLED = True
# HTTPCACHE_EXPIRATION_SECS = 0
# HTTPCACHE_DIR = "httpcache"
# HTTPCACHE_IGNORE_HTTP_CODES = []
# HTTPCACHE_STORAGE = "scrapy.extensions.httpcache.FilesystemCacheStorage"

# Set settings whose default value is deprecated to a future-proof value
REQUEST_FINGERPRINTER_IMPLEMENTATION = "2.7"
TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
FEED_EXPORT_ENCODING = "utf-8"

# 我自己的设置
SPLASH_URL = "http://127.0.0.1:55005"

# 计算机辅助的，我没有进行任何主观输入，反正也看不懂
# 黄之明 2025/05/25 17:00:00
# Splash配置
DOWNLOADER_MIDDLEWARES = {
    "scrapy_splash.SplashCookiesMiddleware": 723,
    "scrapy_splash.SplashMiddleware": 725,
    "scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware": 810,
}
SPIDER_MIDDLEWARES = {
    "scrapy_splash.SplashDeduplicateArgsMiddleware": 100,
}
DUPEFILTER_CLASS = "scrapy_splash.SplashAwareDupeFilter"
DUPEFILTER_DEBUG = True

########################
# kimi的设置
HTTPCACHE_STORAGE = "scrapy_splash.SplashAwareFSCacheStorage"

########################


# 设置请求头
DEFAULT_REQUEST_HEADERS = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
# 设置下载延迟
DOWNLOAD_DELAY = 5
# 设置并发请求数
CONCURRENT_REQUESTS = 16
# 设置请求超时时间
DOWNLOAD_TIMEOUT = 25
# 设置重试次数
RETRY_TIMES = 3
# 设置重试延迟
RETRY_HTTP_CODES = [500, 502, 503, 504, 408]
# 设置重试延迟
RETRY_DELAY = 5
# 设置日志级别
LOG_LEVEL = "INFO"
# 设置日志文件
LOG_FILE = "stock_scrapy.log"
# 设置日志格式
LOG_FORMAT = "%(asctime)s [%(levelname)s] %(message)s"
# 设置日志编码
LOG_ENCODING = "utf-8"
# 设置日志输出到控制台
LOG_STDOUT = True
# 设置日志输出到文件
LOG_FILE = "stock_scrapy.log"
# 设置日志输出到控制台和文件

###########################
# 设置sql数据库基本信息
ITEM_PIPELINES = {
    "stock_scrapy.pipelines.StockScrapyPipeline": 300,
}
MYSQL_HOST = "mysql5.sqlpub.com"
MYSQL_USER = "user_stocks"
MYSQL_PASSWORD = "8Tq2xSfaFAl4AwC3"
MYSQL_DB = "stock_sql"
MYSQL_PORT = 3310
#############################
